#include "lvgl.h"
#include "fr_lv_public_func.h"

const lv_img_dsc_t* switch_ico_img[2] =
{
    IMG_SWITCH_OFF_ICO,
    IMG_SWITCH_ON_ICO,
};
// const uint16_t format_12hour_str[2]=
// {
//     STR_ID_AM,
//     STR_ID_PM,
// };

const uint16_t week_str[7]= //周日->周一
{
    STR_ID_SUM,
    STR_ID_MON,
    STR_ID_TUE,
    STR_ID_WED,
    STR_ID_THU,
    STR_ID_FRI,
    STR_ID_SAT,
};
const lv_img_dsc_t* exercise_type_img[115] =
{
    IMG_EXERCISE_SMALL_001_OUTDOOR_RUNNING             ,
    IMG_EXERCISE_SMALL_002_OUTDOOR_CYCLING             ,
    IMG_EXERCISE_SMALL_003_SKIPPING                    ,
    IMG_EXERCISE_SMALL_004_SWIMMING                    ,
    IMG_EXERCISE_SMALL_005_BADMINTON                   ,
    IMG_EXERCISE_SMALL_006_TABLE_TENNIS                ,
    IMG_EXERCISE_SMALL_007_TENNIS                      ,
    IMG_EXERCISE_SMALL_008_CLIMBING                    ,
    IMG_EXERCISE_SMALL_009_HIKING                      ,
    IMG_EXERCISE_SMALL_010_BASKETBALL                  ,
    IMG_EXERCISE_SMALL_011_SOCCER                      ,
    IMG_EXERCISE_SMALL_012_BASEBALL                    ,
    IMG_EXERCISE_SMALL_013_VOLLEYBALL                  ,
    IMG_EXERCISE_SMALL_014_CRICKET                     ,
    IMG_EXERCISE_SMALL_015_RUGBY                       ,
    IMG_EXERCISE_SMALL_016_HOCKEY                      ,
    IMG_EXERCISE_SMALL_017_DANCE                       ,
    IMG_EXERCISE_SMALL_018_INDOOR_CYCLING              ,
    IMG_EXERCISE_SMALL_019_YOGA                        ,
    IMG_EXERCISE_SMALL_020_SIT_UPS                     ,
    IMG_EXERCISE_SMALL_021_TREADMILL                   ,
    IMG_EXERCISE_SMALL_022_GYMNASTICS                  ,
    IMG_EXERCISE_SMALL_023_ROWING                      ,
    IMG_EXERCISE_SMALL_024_JUMPING_JACK                ,
    IMG_EXERCISE_SMALL_025_FREE_TRAINING               ,
    IMG_EXERCISE_SMALL_026_OUTDOOR_WALKING             ,
    IMG_EXERCISE_SMALL_027_INDOOR_RUN                  ,
    IMG_EXERCISE_SMALL_028_STRENGTH_TRAINING           ,
    IMG_EXERCISE_SMALL_029_STEPPING                    ,
    IMG_EXERCISE_SMALL_030_HORSE_RIDING                ,
    IMG_EXERCISE_SMALL_031_ELLIPTICAL_TRAINER          ,
    IMG_EXERCISE_SMALL_032_TAI_CHI                     ,
    IMG_EXERCISE_SMALL_033_SHUTTLECOCK                 ,
    IMG_EXERCISE_SMALL_034_BOXING                      ,
    IMG_EXERCISE_SMALL_035_OUTDOOR_WALK                ,
    IMG_EXERCISE_SMALL_036_CROSS_COUNTRY_RUNNING       ,
    IMG_EXERCISE_SMALL_037_SKIING                      ,
    IMG_EXERCISE_SMALL_038_ICE_HOCKEY                  ,
    IMG_EXERCISE_SMALL_039_TAEKWONDO                   ,
    IMG_EXERCISE_SMALL_040_VO2MAX_TEST                 ,
    IMG_EXERCISE_SMALL_041_ROWING_MACHING              ,
    IMG_EXERCISE_SMALL_042_STROLLER                    ,
    IMG_EXERCISE_SMALL_043_ATHLETICS                   ,// 占位 复用图标代替
    IMG_EXERCISE_SMALL_043_ATHLETICS                   ,
    IMG_EXERCISE_SMALL_044_WAIST_AND_ABDOMINAL_TRAINING,
    IMG_EXERCISE_SMALL_045_KARATE                      ,
    IMG_EXERCISE_SMALL_046_RELAXATION                  ,
    IMG_EXERCISE_SMALL_047_CROSS_TRAINING              ,
    IMG_EXERCISE_SMALL_048_PILATES                     ,
    IMG_EXERCISE_SMALL_049_CROSS_FIT                   ,
    IMG_EXERCISE_SMALL_050_FUNCTIONAL_TRAINING         ,
    IMG_EXERCISE_SMALL_051_PHYSICAL_TRAINING           ,
    IMG_EXERCISE_SMALL_052_ARCHERY                     ,
    IMG_EXERCISE_SMALL_053_FLEXIBILITY                 ,
    IMG_EXERCISE_SMALL_054_MIXED_AEROBIC               ,
    IMG_EXERCISE_SMALL_055_LATIN_DANCE                 ,
    IMG_EXERCISE_SMALL_056_STREET_DANCE                ,
    IMG_EXERCISE_SMALL_057_FREE_BOXING                 ,
    IMG_EXERCISE_SMALL_058_BALLET                      ,
    IMG_EXERCISE_SMALL_059_AUSTRALIAN_SOCCER           ,
    IMG_EXERCISE_SMALL_060_MARTIAL_ARTS                ,
    IMG_EXERCISE_SMALL_061_STAIR_CLIMBING              ,
    IMG_EXERCISE_SMALL_062_HANDBALL                    ,
    IMG_EXERCISE_SMALL_063_BOWLING                     ,
    IMG_EXERCISE_SMALL_064_SQUASH                      ,
    IMG_EXERCISE_SMALL_065_CURLING                     ,
    IMG_EXERCISE_SMALL_066_HUNTING                     ,
    IMG_EXERCISE_SMALL_067_SNOWBOARDING                ,
    IMG_EXERCISE_SMALL_068_LEISURE_SPORTS              ,
    IMG_EXERCISE_SMALL_069_AMERICAN_FOOTBALL           ,
    IMG_EXERCISE_SMALL_070_HAND_CYCLING                ,
    IMG_EXERCISE_SMALL_071_FISHING                     ,
    IMG_EXERCISE_SMALL_072_FRISBEE                     ,
    IMG_EXERCISE_SMALL_072_FRISBEE                     , //占位 复用图标代替
    IMG_EXERCISE_SMALL_073_GOLF                        ,
    IMG_EXERCISE_SMALL_074_FOLK_DANCE                  ,
    IMG_EXERCISE_SMALL_075_DOWNHILL_SKIING             ,
    IMG_EXERCISE_SMALL_076_SNOW_SPORTS                 ,
    IMG_EXERCISE_SMALL_077_CLAM_MEDIATION_SPORTS       ,
    IMG_EXERCISE_SMALL_078_CORE_TRAINING               ,
    IMG_EXERCISE_SMALL_079_ICE_SKATING                 ,
    IMG_EXERCISE_SMALL_080_FITNESS_GAMES               ,
    IMG_EXERCISE_SMALL_081_GYMNASTICS                  ,
    IMG_EXERCISE_SMALL_082_GROUP_TRAINING              ,
    IMG_EXERCISE_SMALL_083_KICKBOXING                  ,
    IMG_EXERCISE_SMALL_084_LACROSSE                    ,
    IMG_EXERCISE_SMALL_085_FOAM_ROLLING                ,
    IMG_EXERCISE_SMALL_086_WRESTLING                   ,
    IMG_EXERCISE_SMALL_087_FENCING                     ,
    IMG_EXERCISE_SMALL_088_SOFTBALL                    ,
    IMG_EXERCISE_SMALL_089_SINGLE_BAR                  ,
    IMG_EXERCISE_SMALL_090_PARALLEL_BARS               ,
    IMG_EXERCISE_SMALL_091_ROLLER_SKATING              ,
    IMG_EXERCISE_SMALL_092_HULA_HOOP                   ,
    IMG_EXERCISE_SMALL_093_DARTS                       ,
    IMG_EXERCISE_SMALL_094_PICKLEBALL                  ,
    IMG_EXERCISE_SMALL_095_HIIT                        ,
    IMG_EXERCISE_SMALL_096_SHOOTING                    ,
    IMG_EXERCISE_SMALL_097_JUDO                        ,
    IMG_EXERCISE_SMALL_098_TRAMPOLINE                  ,
    IMG_EXERCISE_SMALL_099_SKATEBOARDING               ,
    IMG_EXERCISE_SMALL_100_HOVERBOARD                  ,
    IMG_EXERCISE_SMALL_101_BLADING                     ,
    IMG_EXERCISE_SMALL_102_PARKOUR                     ,
    IMG_EXERCISE_SMALL_103_DIVING                      ,
    IMG_EXERCISE_SMALL_104_SURFING                     ,
    IMG_EXERCISE_SMALL_105_SNORKELING                  ,
    IMG_EXERCISE_SMALL_106_PULL_UPS                    ,
    IMG_EXERCISE_SMALL_107_PUSH_UPS                    ,
    IMG_EXERCISE_SMALL_108_PLANKING                    ,
    IMG_EXERCISE_SMALL_109_ROCK_CLIMBING               ,
    IMG_EXERCISE_SMALL_110_HIGH_JUMP                   ,
    IMG_EXERCISE_SMALL_111_BUNGEE_JUMP                 ,
    IMG_EXERCISE_SMALL_112_LONG_JUMP                   ,
    IMG_EXERCISE_SMALL_113_MARATHON                    ,

};

const uint16_t exercise_type_str[115] =
{
    STR_ID_OUTDOOR_RUN           ,
    STR_ID_OUTDOOR_CYCLE         ,
    STR_ID_JUMP_ROPE             ,
    STR_ID_SWIM                  ,
    STR_ID_BADMINTON             ,
    STR_ID_TABLE_TENNIS          ,
    STR_ID_TENNIS                ,
    STR_ID_MOUNTAINEERING        ,
    STR_ID_HIKING                ,
    STR_ID_BASKETBALL            ,
    STR_ID_FOOTBALL              ,
    STR_ID_BASEBALL              ,
    STR_ID_VOLLEYBALL            ,
    STR_ID_CRICKET               ,
    STR_ID_RUGBY                 ,
    STR_ID_HOCKEY                ,
    STR_ID_DANCE                 ,
    STR_ID_INDOOR_CYCLE          ,
    STR_ID_YOGA                  ,
    STR_ID_SIT_UP                ,
    STR_ID_TREADMILL             ,
    STR_ID_GYMNASTICS            ,
    STR_ID_BOATING               ,
    STR_ID_JUMPING_JACK          ,
    STR_ID_FREE_TRAINING         ,
    STR_ID_OUTDOOR_WALK          ,
    STR_ID_INDOOR_RUN            ,
    STR_ID_STRENGTH_TRAINING     ,
    STR_ID_STEP_TRAINING         ,
    STR_ID_HORSE_RIDING          ,
    STR_ID_ELLIPTICAL_TRAINER    ,
    STR_ID_TAI_CHI               ,
    STR_ID_SHUTTLECOCK           ,
    STR_ID_BOXING                ,
    STR_ID_INDOOR_WALK           ,
    STR_ID_TRAIL_RUNNING         ,
    STR_ID_SKIING                ,
    STR_ID_ICE_HOCKEY            ,
    STR_ID_TAEKWONDO             ,
    STR_ID_VO2MAX_TEST           ,
    STR_ID_ROWING_MACHING        ,
    STR_ID_AIR_WALKER            ,
    STR_ID_HIKING                ,
    STR_ID_ATHLETICS             ,
    STR_ID_WAIST_TRAINING        ,
    STR_ID_KARATE                ,
    STR_ID_COOLDOWN              ,
    STR_ID_CROSS_TRAINING        ,
    STR_ID_PILATES               ,
    STR_ID_CROSS_FIT             ,
    STR_ID_FUNCTIONAL_TRAINING   ,
    STR_ID_PHYSICAL_TRAINING     ,
    STR_ID_ARCHERY               ,
    STR_ID_FLEXIBILITY           ,
    STR_ID_MIXED_CARDIO          ,
    STR_ID_LATIN_DANCE           ,
    STR_ID_STREET_DANCE          ,
    STR_ID_KICKBOXING            ,
    STR_ID_BALLET                ,
    STR_ID_AUSTRALIAN_FOOTBALL   ,
    STR_ID_MARTIAL_ARTS          ,
    STR_ID_STAIRS                ,
    STR_ID_HANDBALL              ,
    STR_ID_BOWLING               ,
    STR_ID_RACQUETBALL           ,
    STR_ID_CURLING               ,
    STR_ID_HUNTING               ,
    STR_ID_SNOWBOARDING          ,
    STR_ID_PLAY                  ,
    STR_ID_AMERICAN_FOOTBALL     ,
    STR_ID_HAND_CYCLING          ,
    STR_ID_FISHING               ,
    STR_ID_DISC_SPORTS           ,
    STR_ID_RUGBY                 ,
    STR_ID_GOLF                  ,
    STR_ID_FOLK_DANCE            ,
    STR_ID_DOWNHILL_SKIING       ,
    STR_ID_SNOW_SPORTS           ,
    STR_ID_MIND_AND_BODY         ,
    STR_ID_CORE_TRAINING         ,
    STR_ID_SKATING               ,
    STR_ID_FITNESS_GAMING        ,
    STR_ID_AEROBICS              ,
    STR_ID_GROUP_TRAINING        ,
    STR_ID_KENDO                 ,
    STR_ID_LACROSSE              ,
    STR_ID_ROLLING               ,
    STR_ID_WRESTLING             ,
    STR_ID_FENCING               ,
    STR_ID_SOFTBALL              ,
    STR_ID_SINGLE_BAR            ,
    STR_ID_PARALLEL_BARS         ,
    STR_ID_ROLLER_SKATING        ,
    STR_ID_HULA_HOOP             ,
    STR_ID_DARTS                 ,
    STR_ID_PICKLEBALL            ,
    STR_ID_HIIT                  ,
    STR_ID_SHOOTING              ,
    STR_ID_JUDO                  ,
    STR_ID_TRAMPOLINE            ,
    STR_ID_SKATEBOARD            ,
    STR_ID_HOVERBOARD            ,
    STR_ID_BLADING               ,
    STR_ID_PARKOUR               ,
    STR_ID_DIVING                ,
    STR_ID_SURFING               ,
    STR_ID_SNORKELING            ,
    STR_ID_PULL_UP               ,
    STR_ID_PUSH_UP               ,
    STR_ID_PLANKING              ,
    STR_ID_ROCK_CLIMBING         ,
    STR_ID_HIGHT_JUMP            ,
    STR_ID_BUNGEE_JUMPING        ,
    STR_ID_LONG_JUMP             ,
    STR_ID_MARATHON              ,
};
const uint16_t measure_text_str[3]=
{
    STR_ID_START_MEASURING,
    STR_ID_MEASURING,
    STR_ID_MEASURE_AGAIN,
};

void lv_img_big_disp(lv_obj_t* parent, const lv_img_dsc_t **src , lv_coord_t x, lv_coord_t y,uint8_t img_num,uint8_t start)
{
    lv_obj_t *cont1 = lv_obj_create(parent);
    lv_obj_remove_style_all(cont1);
    lv_obj_clear_flag(cont1, LV_OBJ_FLAG_SCROLLABLE);
    lv_obj_set_scrollbar_mode(cont1, LV_SCROLLBAR_MODE_OFF);
    lv_obj_set_style_bg_color(cont1,lv_color_black(),0);
    //lv_obj_set_size(cont1,LV_PCT(100),LV_PCT(100));
    lv_obj_set_size(cont1,LV_SIZE_CONTENT,LV_SIZE_CONTENT);
    lv_obj_align(cont1,LV_ALIGN_TOP_LEFT,x,y);
    lv_obj_t *old_obj = NULL;
    for (uint8_t i = 0; i < img_num; i++)
    {
        lv_obj_t *img1 = lv_img_create(cont1);
        lv_img_set_src(img1,src[start+i]);
        if(i == 0)
            lv_obj_set_pos(img1,0,0);
        else
            lv_obj_align_to(img1,old_obj,LV_ALIGN_OUT_BOTTOM_LEFT,0,0);
        old_obj = img1;
    }
    //lv_obj_clear_flag(cont1,LV_OBJ_FLAG_CLICKABLE);
}

lv_obj_t* lv_img_big_create(lv_obj_t* parent, const lv_img_dsc_t **src , lv_coord_t x, lv_coord_t y,uint8_t img_num,uint8_t start)
{
    lv_obj_t *cont1 = lv_obj_create(parent);
    lv_obj_remove_style_all(cont1);
    lv_obj_clear_flag(cont1, LV_OBJ_FLAG_SCROLLABLE);
    lv_obj_set_scrollbar_mode(cont1, LV_SCROLLBAR_MODE_OFF);
    lv_obj_set_size(cont1,LV_SIZE_CONTENT,LV_SIZE_CONTENT);
    //lv_obj_align(cont1,LV_ALIGN_TOP_LEFT,x,y);
    lv_obj_t *old_obj = NULL;

    for(uint8_t i = 0; i < img_num; i++)
    {
        lv_obj_t *img1 = lv_img_create(cont1);
        lv_img_set_src(img1,src[start+i]);
        if(i == 0)
            lv_obj_set_pos(img1,0,0);
        else
            lv_obj_align_to(img1,old_obj,LV_ALIGN_OUT_BOTTOM_LEFT,0,0);
        old_obj = img1;
    }
    //lv_obj_clear_flag(cont1,LV_OBJ_FLAG_CLICKABLE);
    return cont1;

}

lv_obj_t* lv_title_text_create(lv_obj_t* parent ,const char *str,lv_color_t value, uint8_t hour,uint8_t minute)
{
    lv_obj_t *cont1 = lv_obj_create(parent);
    lv_obj_remove_style_all(cont1);
    lv_obj_set_size(cont1,LV_PCT(100),50);

    lv_obj_t* title_label = lv_label_create(cont1);
    lv_label_set_text_fmt(title_label,"%s",str);
    lv_obj_set_style_text_font (title_label, LV_FONT_OSD_MEDIUM_32PX, 0);
    lv_obj_set_style_text_color (title_label, value,0);
    lv_obj_align (title_label, LV_ALIGN_LEFT_MID, 50, 0);

    //时间标签
    lv_obj_t* top_time = lv_label_create(cont1);
    lv_label_set_text_fmt (top_time, "%02d:%02d",hour,minute);
    lv_obj_set_style_text_color (top_time, lv_color_hex(0xffffff),0);
    lv_obj_set_style_text_font (top_time,LV_FONT_MEDIUM_NUMBER_36PX, 0);
    lv_obj_align (top_time, LV_ALIGN_RIGHT_MID, -50, 0);  
    return cont1;
}

void lv_img_change_big_img_src(lv_obj_t* parent, const lv_img_dsc_t **src ,uint8_t img_num,uint8_t start)
{
    for (uint8_t i = 0; i < img_num; i++)
    {
        lv_obj_t *img1 = lv_obj_get_child(parent,i);
        lv_img_set_src(img1,src[start+i]);
    }
}

void convertTo12HourFormat(uint8_t *hours, uint8_t *isAM) {
    if (*hours == 0) {
        *hours = 12;
        *isAM = 1;
    } else if (*hours == 12) {
        *isAM = 0;
    } else if (*hours > 12) {
        *hours -= 12;
        *isAM = 0;
    } else {
        *isAM = 1;
    }
}
uint8_t get_language_id(void)
{
    // return 1;
    return fr_system_get_language();
}

uint8_t get_system_curr_time_hour(void)
{
    //return 12;
    return fr_system_get_time_hour();
}
uint8_t get_system_curr_time_min(void)
{
    //return 20;
    return fr_system_get_time_minute();
}

void roller_mask_event_cb(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t * obj = lv_event_get_target(e);

    static int16_t mask_top_id = -1;
    static int16_t mask_bottom_id = -1;

    if (code == LV_EVENT_COVER_CHECK) {
        lv_event_set_cover_res(e, LV_COVER_RES_MASKED);

    } else if (code == LV_EVENT_DRAW_MAIN_BEGIN) {
        /* add mask */
        const lv_font_t * font = lv_obj_get_style_text_font(obj, LV_PART_MAIN);
        lv_coord_t line_space = lv_obj_get_style_text_line_space(obj, LV_PART_MAIN);
        lv_coord_t font_h = lv_font_get_line_height(font);

        lv_area_t roller_coords;
        lv_obj_get_coords(obj, &roller_coords);
        lv_area_t rect_area;
        rect_area.x1 = roller_coords.x1;
        rect_area.x2 = roller_coords.x2;
        rect_area.y1 = roller_coords.y1;
        rect_area.y2 = roller_coords.y1 + (lv_obj_get_height(obj) - font_h - line_space) / 2;

        lv_draw_mask_fade_param_t * fade_mask_top = lv_mem_buf_get(sizeof(lv_draw_mask_fade_param_t));
        lv_draw_mask_fade_init(fade_mask_top, &rect_area, LV_OPA_TRANSP, rect_area.y1, LV_OPA_COVER, rect_area.y2);
        mask_top_id = lv_draw_mask_add(fade_mask_top, NULL);

        rect_area.y1 = rect_area.y2 + font_h + line_space - 1;
        rect_area.y2 = roller_coords.y2;

        lv_draw_mask_fade_param_t * fade_mask_bottom =lv_mem_buf_get(sizeof(lv_draw_mask_fade_param_t));
        lv_draw_mask_fade_init(fade_mask_bottom, &rect_area, LV_OPA_COVER, rect_area.y1, LV_OPA_TRANSP, rect_area.y2);
        mask_bottom_id = lv_draw_mask_add(fade_mask_bottom, NULL);

    } else if (code == LV_EVENT_DRAW_POST_END) {

        lv_draw_mask_fade_param_t * fade_mask_top = lv_draw_mask_remove_id(mask_top_id);
        lv_draw_mask_fade_param_t * fade_mask_bottom = lv_draw_mask_remove_id(mask_bottom_id);
        lv_mem_buf_release(fade_mask_top);
        lv_mem_buf_release(fade_mask_bottom);

        mask_top_id = -1;
        mask_bottom_id = -1;
    }
}

uint8_t get_time_format_flag(void) //返回时间格式
{
    uint8_t time_format_flag =0; //0 24小时制  1 12小时制
    return time_format_flag;
}


lv_obj_t * draw_dashed_line(lv_obj_t *parent, lv_coord_t x, lv_coord_t y)
{
    static lv_point_t line_points[] ={{0, 2}, {290, 2}};
    lv_obj_t *line = lv_line_create(parent);
    lv_obj_set_style_line_width(line,1,0);
    lv_obj_set_style_line_dash_width(line,4,0);
    lv_obj_set_style_line_dash_gap(line, 4,0);
    lv_obj_set_pos(line, x, y);
    //lv_obj_set_style_border_color(line,lv_color_hex(0x727272),0);
    lv_obj_set_style_line_color(line,lv_color_hex(0x727272),0);
    lv_line_set_points(line,line_points,2);
    return line;
}


//w=368 h=202
lv_obj_t *lv_user_create_chart(lv_obj_t *parent,lv_coord_t x, lv_coord_t y,uint8_t *value,uint32_t *color_buff,uint16_t num)
{

    lv_obj_t *obj_cont = lv_obj_create(parent);
	lv_obj_set_size(obj_cont,368,202);
    lv_obj_set_style_bg_color(obj_cont,lv_color_hex(0x00),0);
	lv_obj_set_style_pad_all(obj_cont,0,0);
//	lv_obj_set_style_border_width(obj_cont,0,0);
//lv_obj_set_style_border_color(obj_cont,lv_color_hex(0x292929),0);
    lv_obj_set_style_border_color(obj_cont,lv_color_black(),0);
	lv_obj_set_style_border_width(obj_cont,2,0);
    lv_obj_set_scrollbar_mode(obj_cont, LV_SCROLLBAR_MODE_OFF);
    lv_obj_set_pos(obj_cont,x,y);
    lv_obj_clear_flag(obj_cont,LV_OBJ_FLAG_SCROLLABLE);

    static lv_point_t line_points[] ={{0, 20}, {290, 20}};
    lv_obj_t * line1;
    line1 = lv_line_create(obj_cont);
    lv_line_set_points(line1, line_points, 2); /*Set the points*/
    lv_obj_set_style_border_color(line1,lv_color_hex(0x666666),0);
    lv_obj_align(line1,LV_ALIGN_BOTTOM_LEFT,59,-30);
    draw_dashed_line(obj_cont,58,131);//绘制虚线
    draw_dashed_line(obj_cont,58,91);
    draw_dashed_line(obj_cont,58,51);
    draw_dashed_line(obj_cont,58,11);
    lv_obj_t *old_obj ;
    for(int i = 0; i <num;i++)
    {
        lv_obj_t *series_obj = lv_obj_create(obj_cont);
        lv_obj_set_style_border_color(series_obj,lv_color_hex(color_buff[i]),0);
        uint16_t ser_val = (uint16_t)((value[i]*3)/2+3);
        lv_obj_set_size(series_obj,8,ser_val);
        lv_obj_set_style_pad_all(series_obj,0,0);
        lv_obj_set_style_radius(series_obj,5,0);
        lv_obj_set_style_bg_color(series_obj,lv_color_hex(color_buff[i]),0);
        if(i==0)
        {
            lv_obj_align_to(series_obj,line1,LV_ALIGN_OUT_LEFT_BOTTOM,10,-1);
        }
        else{
            lv_obj_align_to(series_obj,old_obj,LV_ALIGN_OUT_RIGHT_BOTTOM,4,0);
        }
        old_obj = series_obj;
        //printf("index:%d\r\n",value[i]);
    }
    lv_obj_t* start_time = lv_label_create(obj_cont);
    lv_obj_set_style_text_font(start_time,LV_FONT_SMALL_NUMBER_20PX,0);
    lv_label_set_text_fmt(start_time,"%02d:%02d",0,0);
    lv_obj_set_style_text_color(start_time, lv_color_hex(0x666666),0);
    lv_obj_align(start_time,LV_ALIGN_BOTTOM_LEFT,20,-5);

    lv_obj_t* end_time = lv_label_create(obj_cont);
    lv_obj_set_style_text_font(end_time,LV_FONT_SMALL_NUMBER_20PX,0);
    lv_label_set_text_fmt(end_time,"%02d:%02d",8,0);
    lv_obj_set_style_text_color(end_time, lv_color_hex(0x666666),0);
    lv_obj_align(end_time,LV_ALIGN_BOTTOM_RIGHT,-20,-5);

    lv_obj_t* y_label1 = lv_label_create(obj_cont);
    lv_obj_set_style_text_font(y_label1,LV_FONT_SMALL_NUMBER_20PX,0);
    lv_label_set_text_fmt(y_label1,"%d",100);
    lv_obj_set_style_text_color(y_label1, lv_color_hex(0x666666),0);
    lv_obj_align(y_label1,LV_ALIGN_TOP_LEFT,17,2);

    lv_obj_t* y_label2 = lv_label_create(obj_cont);
    lv_obj_set_style_text_font(y_label2,LV_FONT_SMALL_NUMBER_20PX,0);
    lv_label_set_text_fmt(y_label2,"%d",75);
    lv_obj_set_style_text_color(y_label2, lv_color_hex(0x666666),0);
    lv_obj_align_to(y_label2,y_label1,LV_ALIGN_OUT_BOTTOM_LEFT,0,18);

    lv_obj_t* y_label3 = lv_label_create(obj_cont);
    lv_obj_set_style_text_font(y_label3,LV_FONT_SMALL_NUMBER_20PX,0);
    lv_label_set_text_fmt(y_label3,"%d",50);
    lv_obj_set_style_text_color(y_label3, lv_color_hex(0x666666),0);
    lv_obj_align_to(y_label3,y_label2,LV_ALIGN_OUT_BOTTOM_LEFT,0,18);

    lv_obj_t* y_label4 = lv_label_create(obj_cont);
    lv_obj_set_style_text_font(y_label4,LV_FONT_SMALL_NUMBER_20PX,0);
    lv_label_set_text_fmt(y_label4,"%d",25);
    lv_obj_set_style_text_color(y_label4, lv_color_hex(0x666666),0);
    lv_obj_align_to(y_label4,y_label3,LV_ALIGN_OUT_BOTTOM_LEFT,0,18);

    return obj_cont;

}

bool lv_ui_node_return_to_prev_node(void)
{
	//退到上一级节点
	lv_ui_node_t e_cur;
	if(!lv_ui_node_pop_ex(&e_cur))
    {
        return false;
    }
    lv_refr_now(NULL);
    extern uint8_t lv_ui_node_depth(void);
    if(lv_ui_node_depth() == 0)
    {
        extern void lv_ui_node_hor_return_head(lv_obj_t *parent, lv_ui_node_t *e);
        lv_ui_node_hor_return_head(prj_prev_cont,&e_cur);
    }
    else
    {
        lv_obj_remove_event_cb(prj_prev_cont,NULL);
        lv_obj_clean(prj_prev_cont);
        lv_ui_node_func(prj_prev_cont,&e_cur);
    }
	return true;
}
#define     ENCODE_OFFSET       120
// int16_t encoder_y_pos;
lv_coord_t top_pos;
static bool setting_timer_flag;
static bool user_click_flag;

static void setting_list_timer_cb(lv_timer_t *t)
{
    lv_timer_del(t);
    setting_timer_flag = false;
    lv_obj_t *obj = t->user_data;
    lv_obj_scroll_by(obj, 0, top_pos, LV_ANIM_ON);
}
void fr_lv_encoder_obj_event_cb(lv_event_t *e)
{
	lv_obj_t *target = e->target;
	lv_event_code_t code = e->code;
	uint8_t child_cn = lv_obj_get_child_cnt(target);
	if (!lv_obj_is_valid(target))
		return;

	if(code == LV_EVENT_KEY)
	{
		uint32_t *key = lv_event_get_param(e);
		uint32_t input_key = *key;
		// printf("key:%d\r\n",input_key);
        lv_coord_t obj_y;
        #if 0
		if(input_key == 130)
		{
            lv_obj_t *lastest_child_obj = lv_obj_get_child(target,-1);
            obj_y = lv_obj_get_style_y(lastest_child_obj,0)-lv_obj_get_height(lastest_child_obj)*2;
            printf("obj_y:%d\r\n",obj_y);
            if((encoder_y_pos+ENCODE_OFFSET) < obj_y)
                encoder_y_pos += ENCODE_OFFSET;
            else
                encoder_y_pos = obj_y;
		}
		else if(input_key == 129)
		{
            if((encoder_y_pos-ENCODE_OFFSET) > 0)
                encoder_y_pos -= ENCODE_OFFSET;
            else
                encoder_y_pos = 0;
		}
        #else
        if(setting_timer_flag == false)
        {
            if(input_key == 130)
            {
                lv_obj_scroll_by(target, 0, ENCODE_OFFSET, LV_ANIM_ON);
                user_click_flag = true;
            }
            else if(input_key == 129)
            {
                lv_obj_scroll_by(target, 0, -ENCODE_OFFSET, LV_ANIM_ON);
                user_click_flag = true;
            }
        }
        #endif

	}
	else if (code == LV_EVENT_DELETE)
	{
		lv_group_remove_obj(target);
        group_tail_obj = lv_group_get_focused(prj_group);
		// printf("list,group remove\r\n");
	}
    else if(code == LV_EVENT_SCROLL_END)
    {
        if(user_click_flag == false)
            return;
        user_click_flag = false;

        lv_coord_t top = lv_obj_get_scroll_top(target);
        lv_obj_t *obj = lv_obj_get_child(target,-1);
        // printf("top:%d\r\n",top);
        if(top < 0)
        {
            // printf("in the top!\r\n");
            if(setting_timer_flag == false)
            {
                top_pos = top;
                lv_timer_create(setting_list_timer_cb,100,target);
                setting_timer_flag = true;
            }
        }
        else if((obj->coords.y1+lv_obj_get_height(obj)) <= 448)
        {
            // printf("in the botom\r\n!");
            if(setting_timer_flag == false)
            {
                top_pos = 448 - (obj->coords.y1+lv_obj_get_height(obj));
                top_pos -= lv_obj_get_style_pad_bottom(target,0);
                lv_timer_create(setting_list_timer_cb,100,target);
                setting_timer_flag = true;
            }
        }
    }
}
//uint16_t get_curr_screen_width(void)
//{
//    lv_coord_t hor_res = lv_disp_get_hor_res(lv_disp_get_default()); // 获取屏幕宽度
//    lv_coord_t ver_res = lv_disp_get_ver_res(lv_disp_get_default()); // 获取屏幕高度
//        // 打印屏幕宽度和高度
//    printf("Screen width: %d\n", hor_res);
//    printf("Screen height: %d\n", ver_res);
//}
